package com.accp.jboa.action;

import com.accp.jboa.biz.Reimbursebiz;
import com.accp.jboa.pojo.Reimburse;
import com.accp.jboa.pojo.ReimburseDetail;
import com.accp.jboa.pojo.Status;
import com.accp.jboa.vo.ReimburseAndEmployeeAndDetail;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/reimburse")
public class ReimburseAction {

    @Autowired(required = false)
    private Reimbursebiz reimbursebiz;

    @PostMapping("/insert")
    public Map<String,String> insertSReimburse(@RequestBody Reimburse[] reimburse){
        Map<String,String> map = new HashMap<>();
        int i = reimbursebiz.insertSReimburse(reimburse);
        if (i>0){
            map.put("code","200");
            map.put("msg","报销成功");
            return map;
        }else {
            map.put("code","400");
            map.put("msg","报销失败");
            return map;
        }
    }

    @GetMapping("/queryreimburse/{p}/{s}/{starttime}/{endtime}/{status}")
    public PageInfo<ReimburseAndEmployeeAndDetail> queryAll(@PathVariable int p, @PathVariable int s, @PathVariable String starttime, @PathVariable String endtime,@PathVariable String status){
        return reimbursebiz.queryAll(p,s,starttime,endtime,status);
    }

    @GetMapping("/queryAllStatus")
    public List<Status> queryAllStatus(){
        return reimbursebiz.queryAllStatus();
    }

    @GetMapping("/queryByid/{id}")
    public ReimburseAndEmployeeAndDetail queryByid(@PathVariable Integer id){
        return reimbursebiz.queryByid(id);
    }

    @PostMapping("/upd2")
    public Map<String,String> upd2(@RequestBody ReimburseDetail[] reimburseDetail){
        Map<String,String> map = new HashMap<>();
        int i = reimbursebiz.update(reimburseDetail);
        if (i>0){
            map.put("code","200");
            map.put("msg","修改成功");
            return map;
        }else {
            map.put("code","400");
            map.put("msg","修改失败");
            return map;
        }
    }

    @PostMapping("/insert2")
    public Map<String,String> insert2(@RequestBody ReimburseDetail[] reimburseDetail){
        Map<String,String> map = new HashMap<>();
        Reimburse reimburse = reimbursebiz.insert(reimburseDetail);
        if (reimburse!=null){
            map.put("code","200");
            map.put("msg","新增成功");
            return map;
        }else {
            map.put("code","400");
            map.put("msg","新增失败");
            return map;
        }
    }

}
